package it.antonio.ilpizze.ioc.util;

import it.antonio.ilpizze.ioc.DecorationFactory;
import it.antonio.ilpizze.ioc.Dependencies;
import it.antonio.ilpizze.reflection.FieldAccessor;

public abstract class FieldMatcher extends Matcher<FieldAccessor> {

	public <T> DecorationFactory<T> inject(Injector<FieldAccessor> injector) {
		return DecorationFactory.fields(this, injector);
	}

	public <T> DecorationFactory<T> autowire() {
		return DecorationFactory.fields(this, new Injector<FieldAccessor>() {

			@Override
			public void inject(FieldAccessor field, Object instance, Dependencies dep) {
				Object fieldInstance = dep.get(field.getType());
				field.set(instance, fieldInstance);
			}
		});
		
	}

	public <T> DecorationFactory<T> inject(final Object key) {
		
		return DecorationFactory.fields(this, new Injector<FieldAccessor>() {

			@Override
			public void inject(FieldAccessor field, Object instance, Dependencies dep) {
				Object fieldInstance = dep.get(key);
				field.set(instance, fieldInstance);
			}
		});
		
	}


	
}
